<template>
  <el-header>
    <!-- 右侧导航栏折叠按钮 -->
    <span class="btn-collapse" @click="collapseChage" :title="collapse ? '展开侧边栏' : '收起侧边栏'">
      <i class="el-icon-menu"></i>
    </span>
    <!-- 系统标题 -->
    <h3 class="header-title margin-l-10">Kikyou人力资源管理系统</h3>
    <div class="header-right">
      <!-- 消息中心 -->
      <div class="btn-info">
          <!-- <span slot="content">{{message ? `有${message}条消息` : '消息中心'}}</span> -->
          <router-link to="/chat">
            <i class="el-icon-bell" @click=""></i>
          </router-link>
        <span class="btn-info-tip" v-if="message"></span> 
      </div>
  <!-- 用户头像 -->
  <img :src="user.userFace" class="header-portrait">
      <!-- 用户名下拉菜单 -->
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          {{user.name}}
          <i class="el-icon-caret-bottom"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
            <el-dropdown-item command="settings">设置</el-dropdown-item>
            <el-dropdown-item command="logout">注销登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
    </div>
  </el-header>
</template>

<script>
  import Bus from './bus';
  import {mapState} from 'vuex'
  export default {
    name: "Header",
    data() {
      return {
        collapse: false,
      }
    },
    computed : {
      user() {
        if(this.$store.state.currentAdmin==null){
          return  JSON.parse(window.sessionStorage.getItem('user'));
        }else{
           return this.$store.state.currentAdmin;
        }
      },
    message(){
      //   console.log(this.$store.state.idDotTotoatl+'ddddddddddd'); 
           return this.$store.state.idDotTotoatl    
      },
    },
    methods: {
     msgclik(){
       this.message=false
     },
      // 侧边栏折叠打开效果
      collapseChage() {
        this.collapse = !this.collapse;
        Bus.$emit('collapse', this.collapse);
      },
      // 用户名下拉菜单选择事件
       handleCommand(command) {
      if (command == 'logout') {
        this.$confirm('此操作将注销登录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            // 注销登录
            this.postRequest('/logout')
            // 清空用户信息
            window.sessionStorage.removeItem('tokenStr')
            window.sessionStorage.removeItem('user')
            this.$store.commit('initRoutes', [])
            // this.$store.commit('initUser', []);
            //页面跳转
            this.$router.replace('/')
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消注销',
            })
          })
      }
      if(command == 'userinfo'){
          this.$router.push('/userinfo')
      }
    },
    }
  }
</script>

<style scoped lang="less">
  [class*='el-icon'] {
    cursor: pointer;
  }
  .el-header {
    width: 100%;
   // padding: 0 30px;
    background-color: @headerBgColor;
    color: white;
    font-size: 16px;
    line-height: 53px;
  }
  .header-title, .btn-info {
    display: inline-block;
  }
  .header-title, .btn-collapse, .el-icon-bell {
    font-size: 25px;
  }
  .header-right {
    float: right;
  }
  .btn-collapse {
    vertical-align: sub;
  }
  .btn-info {
    position: relative;
  }
  .btn-info-tip {
    position: absolute;
    top: 10px;
    .circle(8px);
    background-color: #ff464f;
  }
  .el-icon-bell {
    color: white;
    vertical-align: text-top;
  }
  .header-portrait {
    .circle(40px);
    margin: 0 20px;
    vertical-align: middle;
  }
  .el-dropdown-link {
    color: white;
    cursor: pointer;
  }
</style>
